package com.zk.algorithm;

public class ExcelColumnTitleToNumber {

    public int toNumber(String columnTitle) {
        if (columnTitle == null || columnTitle.isEmpty()) {
            return -1;
        }

        int sum = 0;
        for (char c: columnTitle.toCharArray()) {
            sum = sum * 26 + (c - 'A' + 1);
        }

        return sum;
    }

    public static void main(String...args) {
        System.out.println(new ExcelColumnTitleToNumber().toNumber("A"));
        System.out.println(new ExcelColumnTitleToNumber().toNumber("DCS"));
        System.out.println(new ExcelColumnTitleToNumber().toNumber("DBZ"));
    }

}
